package com.buydeem.share.springtxpropagation.service.impl;

import com.buydeem.share.springtxpropagation.dao.AuthorMapper;
import com.buydeem.share.springtxpropagation.model.Author;
import com.buydeem.share.springtxpropagation.service.AuthorService;
import com.buydeem.share.springtxpropagation.service.BookService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.aop.framework.AopContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author zengchao
 * @version 1.0.0
 * @ClassName AuthorServiceImpl.java
 * @Description TODO
 * @createTime 2021年06月21日 20:07:00
 */
@Service
@Slf4j
public class AuthorServiceImpl implements AuthorService {
    @Autowired
    private AuthorMapper authorMapper;
    @Autowired
    private BookService bookService;
    @Autowired
    private AuthorService authorService;
    @Autowired
    private ApplicationContext applicationContext;

    @Override
    public void addAuthor1() {
        Author author = new Author("addAuthor1");
        log.info("插入addAuthor1");
        authorMapper.insertAuthor(author);
        log.info("插入addAuthor1完成");
        bookService.insertBook1();
    }

    @Override
    public void addAuthor2() {
        Author author = new Author("addAuthor2");
        log.info("插入addAuthor2");
        authorMapper.insertAuthor(author);
        log.info("插入addAuthor2完成");
        bookService.insertBook2();
    }

    @Override
    public void addAuthor3() {
        Author author = new Author("addAuthor3");
        log.info("插入addAuthor3");
        authorMapper.insertAuthor(author);
        log.info("插入addAuthor3完成");
        bookService.insertBook3();
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public void addAuthor4() {
        Author author = new Author("addAuthor4");
        log.info("插入addAuthor4");
        authorMapper.insertAuthor(author);
        log.info("插入addAuthor4完成");
        bookService.insertBook4();
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public void addAuthor5() {
        Author author = new Author("addAuthor5");
        log.info("插入addAuthor5");
        authorMapper.insertAuthor(author);
        log.info("插入addAuthor5完成");
        bookService.insertBook5();
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public void addAuthor6() {
        Author author = new Author("addAuthor6");
        log.info("插入addAuthor6");
        authorMapper.insertAuthor(author);
        log.info("插入addAuthor6完成");
        bookService.insertBook6();
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public void addAuthor7() {
        Author author = new Author("addAuthor7");
        log.info("插入addAuthor7");
        authorMapper.insertAuthor(author);
        log.info("插入addAuthor7完成");
        bookService.insertBook7();
    }

    @Override
    public void addAuthor8() {
        Author author = new Author("addAuthor8");
        log.info("插入addAuthor8");
        authorMapper.insertAuthor(author);
        log.info("插入addAuthor8完成");
        addAuthor9();
    }

    @Override
    @Transactional(propagation = Propagation.REQUIRED)
    public void addAuthor9() {
        Author author = new Author("addAuthor9");
        log.info("插入addAuthor9");
        authorMapper.insertAuthor(author);
        log.info("插入addAuthor9完成");
    }

    @Override
    public void addAuthor10() {
        Author author = new Author("addAuthor10");
        log.info("插入addAuthor10");
        authorMapper.insertAuthor(author);
        log.info("插入addAuthor10完成");
        authorService.addAuthor9();
    }

    @Override
    public void addAuthor11() {
        Author author = new Author("addAuthor11");
        log.info("插入addAuthor11");
        authorMapper.insertAuthor(author);
        log.info("插入addAuthor11完成");
        AuthorService temp = (AuthorService) AopContext.currentProxy();
        temp.addAuthor9();
    }

    @Override
    public void addAuthor12() {
        Author author = new Author("addAuthor12");
        log.info("插入addAuthor12");
        authorMapper.insertAuthor(author);
        log.info("插入addAuthor12完成");
        AuthorService temp = applicationContext.getBean(AuthorService.class);
        temp.addAuthor9();
    }
}
